package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TripMapper {
    //1、查询行程表中所有的数据
    @Select("select * from tb_trip")
    @Results({@Result(column="from_address",property="fromAddress")
            ,@Result(column="to_address",property="toAddress")
            ,@Result(column="start_time",property="startTime")})
    List<Trip> queryAll();

    //2、添加用户过年的形成数据
    @Insert("insert into tb_trip values(null,#{username},#{gender}" +
            ",#{idcard},#{fromAddress},#{toAddress},#{startTime})")
    @Results({@Result(column="from_address",property="fromAddress")
            ,@Result(column="to_address",property="toAddress")
            ,@Result(column="start_time",property="startTime")})
    void insert(Trip trip);

    //3、根据ID查询用户的行程数据
    @Select("select * from tb_trip where id=#{id}")
    @Results({@Result(column="from_address",property="fromAddress")
            ,@Result(column="to_address",property="toAddress")
            ,@Result(column="start_time",property="startTime")})
    Trip queryById(@Param("id") Integer id);

    //4、根据ID修改用户的行程数据
    @Update("update tb_trip set username=#{username}" +
            ",gender=#{gender},idcard=#{idcard},from_address=#{fromAddress}"+
            ",to_address=#{toAddress},start_time=#{startTime} where id=#{id}")
    @Results({@Result(column="from_address",property="fromAddress")
            ,@Result(column="to_address",property="toAddress")
            ,@Result(column="start_time",property="startTime")})
    void updateById(Trip trip);
    //5、根据ID删除用户的行程数据
    @Delete("delete from tb_trip where id=#{id}")
    void deleteById(@Param("id") Integer id);
}
